package com.example.demo.controller;

import com.example.demo.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 一个获取用户的例子.
 * @author zhouwei
 */
@RestController
public class UserController {
    @GetMapping("/user/{id}")
    public User findById(@PathVariable String id, HttpServletRequest request) {
        User user = new User();
        user.setUserid(id);
        user.setUsername(request.getUserPrincipal().getName());
        return user;
    }
}
